<?php include incTemplate('header');?>
<script type="text/javascript"
	src="<?php echo HH;?>js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/AjaxFileUploader/ajaxfileupload.js"></script>	
<script type="text/javascript">
var editor;
var attachids = new Array();
var pid = <?php echo $product['id']?>;
$(function(){
	
	editor = fulleditor('content');
	$("#btn_sub").click(function(){
		var content =tinyMCE.get('content').getContent();
		if(content.length<50){
			$.messager.alert('提示','内容不能少于50个字符！'); 
			return;
		}
		
		document.form1.submit();
	});;

	$("#btn_upload").click(function(){
		var procimg = $("#procimg").val();

		if(procimg == ""){
			$.messager.alert('提示','上传图片不能为空！');
			return;
		}
		
		if(!isImg(procimg)){
			$.messager.alert('提示','上传的图片类型不正确！');
			return;
		}
		
		$.ajaxFileUpload
		(
			{
				url:'/admin.php/product/addprocimg',
				secureuri:false,
				fileElementId:'procimg',
				dataType: 'json',
				success: function (data, status)
				{
					if(data.success==true){
						$.messager.alert('提示','上传成功！');

						
						/*
						//设置当前的attachid
						attachids.push(data.insertid);

						var attachvals = $("#attachids").val();
						if(attachvals  ==""){
							attachvals = attachids;
						}else{
							attachvals +=","+ attachids;
						}
						$("#attachids").val(attachvals);
						
						if($("#tr_imglist").css("display") == "none"){
							$("#tr_imglist").show();
						}
						
						var lis = $("#tr_imglist ul li");
						if(lis.length>1){
							$lastli = $("#tr_imglist ul li").last();
							$lastli.append("<li><img onclick='addImg(\'"+data.location+"\')' src=\'/"+data.location+"\' width=\'80\' height=\'80\' /><div>默认<input type=\'radio\' name=\'imgdef\' value=\'/"+data.location+"\' />&nbsp;&nbsp;<input type=\'button\' value=\'删除\' onclick=\'deleteimg("+data.insertid+","+pid+")\' /></div></li>");
						}else{
							$("#tr_imglist ul").append("<li><img onclick='addImg(\'"+data.location+"\')' src=\'/"+data.location+"\' width=\'80\' height=\'80\' /><div>默认<input type=\'radio\' name=\'imgdef\' value=\'/"+data.location+"\' />&nbsp;&nbsp;<input type=\'button\' value=\'删除\' onclick=\'deleteimg("+data.insertid+","+pid+")\' /></div></li>");
						}*/
						
					}else{
						$.messager.alert('提示','上传时有误！');
					}
				},
				error: function (data, status, e)
				{
					$.messager.alert('异常信息',e); 
				}
			}
		)
		
	});
});
function deleteimg(pimgid,pid){
	//var imgitem;
	$.post('/admin.php/product/pimgdelete',{imgid:pimgid,productid:pid},function(data){
		if(data.success){
			$.messager.alert('提示','删除成功！');
			$("#imgitem"+pimgid).remove();
			$lis =$("#tr_imglist ul li");;
			if($lis.length>0){
				$("#tr_imglist").hide();
			}
		}else{
			$.messager.alert('提示','删除操作失败！');
		}
	},'json');
	
}
</script>
</head>
<body class="body" >
<form action="/admin.php/product/productupdatedo" id="form1" name="form1" method="post">
<input type="hidden" name="id" value="<?php echo $product['id'];?>"/>
<input type="hidden" name="attachids" id="attachids" value="<?php echo $imgids;?>"/>
<table class="tab_form">
	<tr>
		<td>
			标题：<input type="text" name="title" id="title" class="w_250" value="<?php echo $product['pname'];?>" />
		</td>
	</tr>
	<tr>
		<td>
		<textarea name="content" id="content" style="width:100%;height:450px; "><?php echo $product['pdesc'];?></textarea>
		</td> 
	</tr>
	<tr id="tr_upload">
		<td><input type="file" name="procimg" id="procimg" size="35"/>&nbsp;&nbsp;<input type="button" id="btn_upload" value="上传"/></td>
	</tr>
	<?php 
	if(sizeof($procimgs) >=1){
		?>
		<tr id="tr_imglist">
		<?php
	}else{
		?>
		<tr id="tr_imglist" style="display:none;">
		<?php
	}
	?>
		<td>
		<div id="div_imglist">
			<ul>
				<?php 
	if(sizeof($procimgs) >=1){
		foreach ($procimgs as $img){
		?>
		<li id="imgitem<?php echo $img['id'];?>">
		<div class="imgdiv"><img width="100px" height="100px" onclick="addImg('<?php echo $img['imgurl'];?>')"  src="/<?php echo $img['imgurl'];?>" /></div>
		<div>默认<input type="radio" name="imgdef" <?php if($product['imgdef']==$img['imgurl']){?>checked="checked" <?php }?> value="<?php echo $img['imgurl'];?>"/>&nbsp;&nbsp;<input type="button" value="删除" onclick="deleteimg('<?php echo $img['id'];?>',<?php echo $product['id'];?>)" /></div>
		</li>
		<?php
		}
	}
		?>
			</ul>
		</div>
		</td>
	</tr>
	<tr>
		<td>
	<input type="button" id="btn_sub" value="编辑"/>
		</td>
	</tr>
</table>
</form>
</body>
</html>